package main

import "fmt"

type worker struct {
	in chan int
	done chan bool
}

func doWork(id int, c chan int, done chan bool)  {
	for n := range c {
		fmt.Printf("worder %d received %c \n", id, n)
		go func() { done <- true }()
	}
}

func createWorker(id int) worker {
	w := worker{
		in: make(chan int),
		done:make(chan bool),
	}

	go doWork(id , w.in, w.done)

	return w
}

func chanDemo()  {
	var workers [20]worker
	for i :=0; i<20; i++ {
		workers[i] = createWorker(i)
	}

	for i, worker := range workers{
		worker.in <- 'a' +i
	}

	for i, worker := range workers{
		worker.in <- 'A' +i
	}

	for _, worker := range workers{
		<-worker.done
		<-worker.done
	}
}

func main()  {
	chanDemo()
}